package com.itheima.a01test5;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        /*
        客户端发送数据 接收反馈
        服务端进行接收 进行反馈
        */
        //1.创建对象
        Socket socket = new Socket("127.0.0.1", 10000);

        //2.进行数据的发送
        String str = "见到你很高兴！";
        OutputStream os = socket.getOutputStream();
        os.write(str.getBytes());

        //发送结束标志
        socket.shutdownOutput();

        //3.接收反馈的数据
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int b;
        while ((b = isr.read()) != -1) {
            System.out.print((char) b);
        }
        //进行关流
        socket.close();
    }
}
